import os
from http import HTTPStatus
from dashscope import Application
responses = Application.call(
            # 若没有配置环境变量，可用百炼API Key将下行替换为：api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中，以减少API Key泄露风险。
        api_key="sk-b8575714afad46d2a2cd5156aa11b6b5",
        app_id='8381bee7d9f74316864c0be3b2211223',  # 替换为实际的应用 ID
            prompt='你是谁？',
            stream=True,  # 流式输出
            incremental_output=True)  # 增量输出

for response in responses:
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        print(f'code={response.status_code}')
        print(f'message={response.message}')
        print(f'请参考文档：https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
    else:
        print(response)
        # print(f'{response.output.text}')  # 处理只输出文本text